<?php


namespace App\Services;


use Illuminate\Support\Facades\Redis;

class RedisTable
{

    public static function get(string $key)
    {
        return Redis::get($key);
    }

    public static function save(string $key, string $value, int $ttl = 0)
    {
        Redis::set($key,$value);
        if ($ttl > 0){
            self::setExpire($key,$ttl);
        }

        return $value;
    }

    public static function del(string $key)
    {
        return Redis::del($key);
    }


    public static function objectTable(string $key)
    {
        return Redis::hgetall($key);
    }

    public static function objectTableSave(string $key,$data,int $ttl = 0)
    {
        Redis::hmset($key,$data);
        if ($ttl >0) self::setExpire($key,$ttl);

        return $data;
    }

    public static function objectTableDelete(string $key,$k)
    {
        return Redis::hdel($key,$k);
    }

    public static function setExpire(string $key,int $ttl)
    {
        return Redis::command('expire',[$key,$ttl]);
    }

}
